package com.yunxi.controller.vip;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.vip.pojo.StoVehicleExpVO;
import com.yunxi.vip.service.StoVehicleExpDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 体验车库存 前端控制器
 * </p>
 *
 * @author
 * @since 2019-09-25
 */
@RestController
@RequestMapping("/admin/stoVehicleExp")
@Api(tags = "pms:stovehicleexp", description = "体验车库存接口")
public class StoVehicleExpController {
    private static final Logger logger = LoggerFactory.getLogger(StoVehicleExpController.class);

    @Autowired
    StoVehicleExpDubboService pmsStoVehicleExpDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "(厂端)查询体验车库存分页")
    public ApiResult page(StoVehicleExpVO StoVehicleExpVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.findPageByVO(StoVehicleExpVO, pageNum, pageSize));
    }

    @GetMapping("/pageByPartner")
    @ApiOperation(value = "(店端)查询体验车库存分页")
    public ApiResult pageByPartner(StoVehicleExpVO stoVehicleExpVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoVehicleExpVO.setPartnerCode(loginInfo.getPartnerCode());
        stoVehicleExpVO.setHireStatusNot(3);
        stoVehicleExpVO.setVehicleStatus(5);
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.findPageByVO(stoVehicleExpVO, pageNum, pageSize));
    }

    @GetMapping("/pageByFactory")
    @ApiOperation(value = "(店端)查询体验车库存分页")
    public ApiResult pageByFactory(StoVehicleExpVO stoVehicleExpVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoVehicleExpVO.setHireStatusNot(3);
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.findPageByVO(stoVehicleExpVO, pageNum, pageSize));
    }

    @GetMapping("/pageByPartnerFinance")
    @ApiOperation(value = "(金融伙伴)查询体验车库存分页")
    public ApiResult pageByPartnerFinance(StoVehicleExpVO stoVehicleExpVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {
        stoVehicleExpVO.setPartnerFinance(loginInfo.getPartnerCode());
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.findPageByVO(stoVehicleExpVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "查询体验车库存列表")
    public ApiResult list(StoVehicleExpVO StoVehicleExpVO) throws Exception {
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.listByVo(StoVehicleExpVO));
    }

    @GetMapping("/pageByCheckSales")
    @ApiOperation(value = "大客户核销列表")
    public ApiResult pageByCheckSales(StoVehicleExpVO stoVehicleExpVO, Integer pageNum, Integer pageSize, @CurrentUser LoginInfo loginInfo) throws Exception {

        if(StringUtils.isNotEmpty(loginInfo.getPartnerCode())){
            stoVehicleExpVO.setPartnerCode(loginInfo.getPartnerCode());
            stoVehicleExpVO.setSubmitType(0);
        }else{
            //stoVehicleExpVO.setSubmitType(1);
        }

        stoVehicleExpVO.setPartnerCode(loginInfo.getPartnerCode());
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.pageByCheckSales(stoVehicleExpVO, pageNum, pageSize));
    }

    @PostMapping("/checkSales")
    @ApiOperation(value = "大客户核销审核")
    public ApiResult checkSales(@RequestBody StoVehicleExpVO StoVehicleExpVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        pmsStoVehicleExpDubboService.checkSales(StoVehicleExpVO);
        return ResponseUtil.ok("success");
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个体验车库存")
    public ApiResult load(StoVehicleExpVO StoVehicleExpVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.getById(StoVehicleExpVO.getExpId()));
    }

    @GetMapping("/getByCas")
    @ApiOperation(value = "读取单个体验车库存")
    public ApiResult getByCas(StoVehicleExpVO StoVehicleExpVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(pmsStoVehicleExpDubboService.getByCas(StoVehicleExpVO.getExpId()));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存体验车库存信息")
    public ApiResult save(@RequestBody StoVehicleExpVO StoVehicleExpVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        pmsStoVehicleExpDubboService.saveOrUpdate(StoVehicleExpVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/updateStatus")
    @ApiOperation(value = "保存体验车库存信息")
    public ApiResult updateStatus(@RequestBody StoVehicleExpVO StoVehicleExpVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        int code = pmsStoVehicleExpDubboService.updateStatus(StoVehicleExpVO);
        if(code!=200){
            ResponseUtil.fail(12998,"车辆还未交车，请交车后进行出租操作！");
        }
        return ResponseUtil.ok("success");
    }

    @PostMapping("/saveAttach")
    @ApiOperation(value = "保存体验车库存信息")
    public ApiResult saveAttach(@RequestBody StoVehicleExpVO stoVehicleExpVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        pmsStoVehicleExpDubboService.saveOrUpdate(stoVehicleExpVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除体验车库存")
    public ApiResult del(@RequestBody List<StoVehicleExpVO> StoVehicleExpVOList) throws Exception {
        pmsStoVehicleExpDubboService.removeByListVo(StoVehicleExpVOList);
        return ResponseUtil.ok("success");
    }
/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(pmsStoVehicleExpDubboService.findMapByList(params));
}*/
}
